﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Logic.SocialNetworks.EventBrite
{
    public class Users : List<User>
    {
        public Users(XmlDocument XmlDocument) 
        {
            foreach (XmlElement item in XmlDocument.DocumentElement)
            {
                User u = new User(item);
                base.Add(u);

            }
        }

    }
    public class User
    {
        #region User Arguments
        /// <summary>
        /// The user ID.
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// Processing status.
        /// </summary>
        public string Status { get; set; }
        /// <summary>
        /// Processing message.
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// The user email address.
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// The user password. (needs to be at least 4 characters long)
        /// </summary>
        public string Password { get; set; }
        /// <summary>
        /// The user key is a unique string assigned by Eventbrite which identifies the user making an API call.
        /// This replaces basic username/password authentication.
        /// </summary>
        public string UserKey { get; set; }
        /// <summary>
        /// The first name of the user.
        /// </summary>
        public string FirstName { get; set; }
        /// <summary>
        /// The last name of the user.
        /// </summary>
        public string LastName { get; set; }
        /// <summary>
        /// The date and time the user was created, in ISO 8601 format (e.g., "2007-12-31 23:59:59").
        /// </summary>
        public string DateCreated { get; set; }
        /// <summary>
        /// The date and time the user was last modified, in ISO 8601 format (e.g., "2007-12-31 23:59:59").
        /// </summary>
        public string DateModified { get; set; }
        /// <summary>
        /// This method lists the events created by this user.
        /// </summary>
        public Events Events { get; set; }

        #endregion

        internal User(XmlElement XmlElement)
        {
            CreateUser(XmlElement);
        }
        public User(XmlDocument XmlDocument) 
        { CreateUser(XmlDocument.DocumentElement); }

        private void CreateUser(XmlElement XmlElement)
        {
            foreach (XmlElement item in XmlElement)
            {
                switch (item.Name)
                {
                    case "id":
                        this.ID = Convert.ToInt32(item.InnerText);
                        break;
                    case "date_created":
                        this.DateCreated= item.InnerText;
                        break;
                    case "date_modified":
                        this.DateModified = item.InnerText;
                        break;
                    case "email":
                        this.Email = item.InnerText;
                        break;
                    case "events":
                        this.Events.Add(new Event(item));
                        break;
                    case "first_name":
                        this.FirstName = item.InnerText;
                        break;
                    case "last_name":
                        this.LastName = item.InnerText;
                        break;
                    case "message":
                        this.Message = item.InnerText;
                        break;
                    case "password":
                        this.Password = item.InnerText;
                        break;
                    case "status":
                        this.Status = item.InnerText;
                        break;
                    case "user_key":
                        this.UserKey = item.InnerText;
                        break;
                    default:
                        break;
                }
            }

        }
    }
}
